#include "StdAfx.h"
#include "SRObjModel.h"
#include "SRObjModelLoader.h"

using namespace sora;
using std::vector;
using std::auto_ptr;
using std::string;
using matsu::vec4;
using matsu::vec3;
using matsu::vec2;

TEST(ObjNodeData, FaceVertex)
{
	//vertex
	string line = "f 1 2 3 4";
	ObjNodeData data(line);

	EXPECT_EQ(ObjNodeKeywordFace, data.keyword());
	EXPECT_EQ(false, data.useNormal);
	EXPECT_EQ(false, data.useTex);
	EXPECT_EQ(4, data.intCnt());
	EXPECT_EQ(4, data.numVertex());
	EXPECT_EQ(1, data.singleVertexNeedInt());

	EXPECT_EQ(1, data.vertex(0));
	EXPECT_EQ(2, data.vertex(1));
	EXPECT_EQ(3, data.vertex(2));
	EXPECT_EQ(4, data.vertex(3));
}
TEST(ObjNodeData, FaceVertexNormal)
{
	//vertex-normal
	string line = "f 1//1 2//2 3//3 4//5";
	ObjNodeData data(line);

	EXPECT_EQ(ObjNodeKeywordFace, data.keyword());
	EXPECT_EQ(true, data.useNormal);
	EXPECT_EQ(false, data.useTex);
	EXPECT_EQ(8, data.intCnt());
	EXPECT_EQ(4, data.numVertex());
	EXPECT_EQ(2, data.singleVertexNeedInt());

	EXPECT_EQ(1, data.vertex(0));
	EXPECT_EQ(1, data.normal(0));

	EXPECT_EQ(2, data.vertex(1));
	EXPECT_EQ(2, data.normal(1));

	EXPECT_EQ(3, data.vertex(2));
	EXPECT_EQ(3, data.normal(2));

	EXPECT_EQ(4, data.vertex(3));
	EXPECT_EQ(5, data.normal(3));
}
TEST(ObjNodeData, FaceVertexTex)
{
	string line = "f 1/1 2/2 3/3 4/5";
	ObjNodeData data(line);

	EXPECT_EQ(ObjNodeKeywordFace, data.keyword());
	EXPECT_EQ(false, data.useNormal);
	EXPECT_EQ(true, data.useTex);
	EXPECT_EQ(8, data.intCnt());
	EXPECT_EQ(4, data.numVertex());
	EXPECT_EQ(2, data.singleVertexNeedInt());

	EXPECT_EQ(1, data.vertex(0));
	EXPECT_EQ(1, data.tex(0));

	EXPECT_EQ(2, data.vertex(1));
	EXPECT_EQ(2, data.tex(1));

	EXPECT_EQ(3, data.vertex(2));
	EXPECT_EQ(3, data.tex(2));

	EXPECT_EQ(4, data.vertex(3));
	EXPECT_EQ(5, data.tex(3));
}
TEST(ObjNodeData, FaceVertexTexNormal)
{
	string line = "f 1/1/1 2/2/2 3/3/3 4/5/6";
	ObjNodeData data(line);

	EXPECT_EQ(ObjNodeKeywordFace, data.keyword());
	EXPECT_EQ(true, data.useNormal);
	EXPECT_EQ(true, data.useTex);
	EXPECT_EQ(12, data.intCnt());
	EXPECT_EQ(4, data.numVertex());
	EXPECT_EQ(3, data.singleVertexNeedInt());

	EXPECT_EQ(1, data.vertex(0));
	EXPECT_EQ(1, data.tex(0));
	EXPECT_EQ(1, data.normal(0));

	EXPECT_EQ(2, data.vertex(1));
	EXPECT_EQ(2, data.tex(1));
	EXPECT_EQ(2, data.normal(1));

	EXPECT_EQ(3, data.vertex(2));
	EXPECT_EQ(3, data.tex(2));
	EXPECT_EQ(3, data.normal(2));

	EXPECT_EQ(4, data.vertex(3));
	EXPECT_EQ(5, data.tex(3));
	EXPECT_EQ(6, data.normal(3));

}
